<template>
	<view class="p_full p_bg_f3 p_b_128">
		<view class="set_main">
			<view class="set_top">
				<orderContent :item="fileInfo" :isPreview="false"></orderContent>
			</view>
			<view class="tips_wrapper p_flex2">
				<image src="https://dy.sykj365.com/uploads/mini/laba.png" class="p_img_32 p_margin_r_16"></image>
				<swiper autoplay circular vertical :interval="2000" style="flex: 1;height: 100%;">
					<swiper-item v-for="(item, index) in systemNotice" :key="index">
						<view class="p_font_24 p_color_05b570 p_flex_1 p_one_text"
							style="height: 100%;line-height: 50rpx;">{{item}}</view>
					</swiper-item>
				</swiper>
			</view>
			<view class="set_content">
				<view class="set_title">纸张</view>
				<view class="set_wrapper">
					<view :class="{'active': formData.brand == item.name}" v-for="item in brandList" :key="item.id"
						@click="getBrandChoose(item)">
						{{item.name}}
					</view>
				</view>
				<view class="set_des" v-if="brandDes">*{{brandDes}}</view>
				<view class="set_title">纸型</view>
				<view class="set_wrapper">
					<view :class="{'active': formData.paper == item.name, 'huise': item.isChoose == undefined}"
						v-for="item in paperList" :key="item.id" @click="getPaperChoose(item)">
						{{item.name}}
					</view>
				</view>
				<view class="set_des" v-if="paperDes">*{{paperDes}}</view>
				<!-- <view v-if="pageTurningType == 2">
					<view class="set_title">翻页方向</view>
					<view class="set_wrapper">
						<view :class="{'active': formData.page_turning == '横向翻页'}" @click="getPageTurning('横向翻页')">横向翻页
						</view>
						<view :class="{'active': formData.page_turning == '竖向翻页'}" @click="getPageTurning('竖向翻页')">竖向翻页
						</view>
					</view>
					<view class="set_des">*发现文件内有页面方向不一致，请自行选择方向，建议选择单面打印</view>
				</view> -->
				<view class="set_title">单双面</view>
				<view class="set_wrapper">
					<view :class="{'active': formData.single_double == item.id, 'huise': item.isChoose == undefined}"
						v-for="item in singleList" :key="item.id" @click="getSingle(item)">{{item.name}}</view>
				</view>
				<view class="set_title">
          打印方式
          <view v-if="previewUrl" class="preview-btn" @click="handlePreview">效果图</view>
        </view>
				<view class="set_wrapper">
					<view :class="{'active': formData.colour == item.name, 'huise': item.isChoose == undefined}"
						v-for="item in colourList" :key="item.id" @click="getColourChoose(item)">
						{{item.name}}
					</view>
				</view>
				<view class="set_des" v-if="colourDes">*{{colourDes}}</view>
				<view class="set_title">多页合一<text class="p_color_b2 p_font_24">(缩印)</text></view>
				<view class="set_wrapper">
					<view :class="{'active': formData.reduction_printing == item.name}" v-for="item in reduceList"
						:key="item.id" @click="getReduceChoose(item)">{{item.name}}</view>
				</view>
				<view class="set_des" v-if="reductionDes">*{{reductionDes}}</view>
				<view class="set_title">装订方式</view>
				<view class="p_flex11">
					<view class="set_wrapper">
						<view :class="{'active': item === formData.binding_type, 
							'huise': formData.paper == 'B5' && item == '圈装', 
							'huise': formData.paper == 'A3' && (item == '圈装' || item == '胶装'),
							'huise': infoPage > dsdMaxNum && item === '订书钉'}" v-for="(item, index) in typeList" :key="index"
							@click="getTypeChoose(item)">{{item}}</view>
					</view>
					<image src="https://dy.sykj365.com/uploads/mini/zhuangding@2x.png" class="p_img_192 p_margin_t_16"
						v-if="formData.binding_type == '不装钉'"></image>
					<image :src="yuming + '/uploads/mini/3.jpg'" class="p_img_192 p_margin_t_16"
						style="border-radius: 16rpx;" v-if="formData.binding_type == '订书钉'"></image>
					<image :src="yuming + '/uploads/mini/1.jpg'" class="p_img_192 p_margin_t_16"
						style="border-radius: 16rpx;" mode="aspectFill" v-if="formData.binding_type == '圈装'"></image>
					<image :src="yuming + '/uploads/mini/2.jpg'" class="p_img_192 p_margin_t_16"
						style="border-radius: 16rpx;" v-if="formData.binding_type == '胶装'"></image>
				</view>
				<view v-if="formData.binding_type === '胶装'">
					<view class="set_title">封面类型</view>
					<view class="set_wrapper">
						<view :class="{'active': bindingName === '皮纹纸'}" @click="getBindingType('皮纹纸')">皮纹纸</view>
						<view :class="{'active': bindingName === '铜版纸'}" @click="getBindingType('铜版纸')">铜版纸</view>
					</view>
					<view class="p_font_24 set_tectorial" v-if="bindingName === '铜版纸'">
						<view class="p_flex2">
							<image src="https://dy.sykj365.com/uploads/mini/xuanzhong@2x.png" class="p_img_48"
								v-if="formData.film_covering === '覆膜'"></image>
							<image src="https://dy.sykj365.com/uploads/mini/weixuanzhong@2x.png" class="p_img_48" v-else
								@click="formData.film_covering = '覆膜';getPrice()"></image>
							<view class="p_margin_l_8">覆膜</view>
						</view>
						<view class="p_flex2 p_margin_l_72">
							<image src="https://dy.sykj365.com/uploads/mini/xuanzhong@2x.png" class="p_img_48"
								v-if="formData.film_covering === '不覆膜'"></image>
							<image src="https://dy.sykj365.com/uploads/mini/weixuanzhong@2x.png" class="p_img_48" v-else
								@click="formData.film_covering = '不覆膜';getPrice()"></image>
							<view class="p_margin_l_8">不覆膜</view>
						</view>
					</view>
					<view class="p_margin_t_48" v-if="bindingName === '皮纹纸'">
						<view class="set_title" style="margin-bottom: 4rpx;">封面颜色</view>
						<view class="p_flex3">
							<view class="set_pitch" v-for="(item, index) in coverColors" :key="index"
								@click="getCoverColor(index)">
								<view :class="{'active': item.color_value === '#FFFFFF'}"
									:style="'background: ' + item.color_value"></view>
								<view>{{item.name}}</view>
								<view v-if="formData.color == item.name"></view>
							</view>
						</view>
					</view>
					<view class="set_title" style="margin-top: 36rpx;">封面内容</view>
					<view class="set_wrapper">
						<view :class="{'active': coverIndex === index}" v-for="(item, index) in coverList" :key="index"
							@click="getChangeType(index)">
							{{item}}
						</view>
					</view>
					<!-- 文字封面 -->
					<view class="p_margin_t_32 p_flex2" v-show="coverIndex === 0">
						<view class="text_wrapper">
							<textarea maxlength="10" v-model="textUrl" placeholder="请输入封面文字(10个字以内)"
								placeholder-class="p_font_28 p_color_b2" class="p_font_28"></textarea>
						</view>
						<!-- <view class="text_wrapper">
							<navigator url="/pages/index/coverText" hover-class="none" class="text_add p_flex8"
								v-if="!textUrl">
								<image src="https://dy.sykj365.com/uploads/mini/jia@2x.png" class="p_img_40"></image>
								<view class="p_font_26 p_color_b2 p_margin_t_30">编辑封面</view>
							</navigator>
							<image :src="textUrl.charAt(0) == '/'?imgHost + textUrl: textUrl" mode="heightFix"
								class="text_img" v-else></image>
						</view>
						<view class="p_margin_l_24 btn_wrapper p_font_26" v-if="textUrl">
							<navigator
								:url="'/pages/index/preview?url=' + (textUrl.charAt(0) == '/'?imgHost + textUrl: textUrl)"
								hover-class="none">预览</navigator>
							<navigator :url="'/pages/index/coverText?coverInfo=' + JSON.stringify(coverInfo)"
								hover-class="none">编辑
							</navigator>
						</view> -->
					</view>
					<!-- 上传封面封面 -->
					<view class="p_margin_t_32 p_flex2" v-show="coverIndex === 2">
						<view class="text_wrapper" @click="getImgUp">
							<view class="text_add p_flex8" v-if="!imgsUrl">
								<image src="https://dy.sykj365.com/uploads/mini/jia@2x.png" class="p_img_40"></image>
								<view class="p_font_26 p_color_b2 p_margin_t_30">编辑封面</view>
							</view>
							<image :src="imgsUrl.charAt(0) == '/'?imgHost + imgsUrl: imgsUrl" mode="heightFix"
								class="text_img" v-else></image>
						</view>
						<!-- <view class="text_wrapper">
							<navigator url="/pages/index/coverImg" hover-class="none" class="text_add p_flex8"
								v-if="!imgsUrl">
								<image src="https://dy.sykj365.com/uploads/mini/jia@2x.png" class="p_img_40"></image>
								<view class="p_font_26 p_color_b2 p_margin_t_30">编辑封面</view>
							</navigator>
							<image :src="imgsUrl.charAt(0) == '/'?imgHost + imgsUrl: imgsUrl" mode="heightFix"
								class="text_img" v-else></image>
						</view>
						<view class="p_margin_l_24 btn_wrapper p_font_26" v-if="imgsUrl">
							<navigator
								:url="'/pages/index/preview?url=' + (imgsUrl.charAt(0) == '/'?imgHost + imgsUrl: imgsUrl) + '&type=' + (imgsCoverInfo.coverType?imgsCoverInfo.coverType == 2?true: '': '') "
								hover-class="none">预览</navigator>
							<navigator :url="'/pages/index/coverImg?coverInfo=' + JSON.stringify(imgsCoverInfo)"
								hover-class="none">编辑
							</navigator>
						</view> -->
					</view>
				</view>
				<view class="set_title" :style="formData.binding_type !== '胶装'?'margin-top:0': ''">打印范围<text
						class="p_color_b2 p_font_24">(可添加多个)</text></view>
				<view class="set_wrapper">
					<view class="p_flex2" :class="{'active': !formData.print_range}" v-if="isPrintsRange"
						@click="popShow = true">选择起始页<image src="https://dy.sykj365.com/uploads/mini/xiala@2x.png"
							class="p_img_32 p_margin_l_8"></image>
					</view>
					<view :class="{'active': formData.print_range == item}" v-for="(item, index) in printRangeList"
						:key="index" @click="getPages(item, true)">
						{{item}}
						<image src="https://dy.sykj365.com/uploads/mini/cha@2x.png" class="p_img_48"
							style="position: absolute;right: 0;top: 0;" v-if="index != 0"
							@click.stop="getDel(item, index)">
						</image>
					</view>
				</view>
				<view class="set_title">打印份数</view>
				<view class="p_bg_f3 p_flex2 p_margin_t_16" style="width: 256rpx;">
					<image src="https://dy.sykj365.com/uploads/mini/jian@2x.png" class="p_img_68" @click="getChooseNum(0)"></image>
					<view class="p_flex_1 p_flex7 p_font_28">
						<input type="number" v-model="formData.num" class="p_text_c" @blur="getNumChange" />
					</view>
					<image src="https://dy.sykj365.com/uploads/mini/jia3@2x.png" class="p_img_68" @click="getChooseNum(1)"></image>
				</view>
				<view class="set_title" v-if="fileInfo.user_document == 0">加入文档库</view>
				<switch v-if="fileInfo.user_document == 0" :checked="checked" @change="(e)=>checked=e.detail.value" />
			</view>
		</view>
		<view class="p_text_c p_font_28 p_margin_b_32 p_flex7">
			<view class="p_tb_8" @click="copyShow = true">复制一份</view>
		</view>
		<bottomView btnText1="确认配置" btnText2="预览" @getSubmit="getSetData" @getClear="getClear">
			<view class="p_flex2">
				<view class="p_font_24 p_color_7a p_margin_r_16">总计:</view>
				<view class="p_font_32 p_color_ff5555"><text class="p_font_20 p_margin_r_8">¥</text>{{allPrice}}</view>
			</view>
		</bottomView>
		<!-- 起始页 -->
		<van-popup :show="popShow" position="bottom" round>
			<view class="p_font_24 p_color_05b570 p_text_c pick_text">
				页码以文件预览界面上部数字为准，并非文件内容上页码数字</view>
			<van-picker show-toolbar title="选择起始页" :columns="columns" @cancel="popShow = false"
				@confirm="getPageConfirm" />
		</van-popup>
		<!--  -->
		<tips :tipsShow="coverTips" messages="切换选项会删除封面文件" confirmText="确定" cancelText="取消"
			@getDialogCancel="coverTips = false" @getDialogConfirm="getDialogConfirm"></tips>
		<tips :tipsShow="jiaozhuangShow" :messages="'胶装单册不能超过' + jzMaxNum + '张纸,点击查看解决方案'" confirmText="解决方案"
			cancelText="取消" @getDialogCancel="jiaozhuangShow = false" @getDialogConfirm="getLook"></tips>
		<tips :tipsShow="dingshudingShow"
			:messages="formData.binding_type + '单册不能超过' + (formData.binding_type === '订书钉'?dsdMaxNum: qzMaxNum) + '张纸,点击查看解决方案'"
			confirmText="解决方案" cancelText="取消" @getDialogCancel="dingshudingShow = false" @getDialogConfirm="getLook2">
		</tips>
		<!-- 复制一份 -->
		<tips :tipsShow="copyShow" title="请确认" messages="确定复制一份此文件到列表中吗？" confirmText="确定" cancelText="取消"
			@getDialogCancel="copyShow = false" @getDialogConfirm="getDialogCopy"></tips>
		<tips :tipsShow="copy1Show" title="提示" messages="已成功复制，请前往列表查看! 点击保存将保存当前设置并返回列表! " confirmText="保存"
			cancelText="继续修改" @getDialogCancel="copy1Show = false" @getDialogConfirm="getSubmit"></tips>
		<tips :tipsShow="lookShow" title="提示" messages="请先点击预览按钮查看样式是否有转变，如果样式不对，请自行转成pdf再上传。" confirmText="预览"
			cancelText="取消" @getDialogCancel="lookShow = false" @getDialogConfirm="getLookSubmit"></tips>
		<tips :tipsShow="choosePaper" title="提示" messages="80克复印纸纸质更好，书写更流畅不易透纸。" confirmText="选复印纸" cancelText="选普通纸"
			@getDialogCancel="choosePaper = false" @getDialogConfirm="getPaperSubmit"></tips>
	</view>
</template>

<script>
	import tips from '../../components/tips.vue';
	import bottomView from '../../components/bottomView.vue';
	import orderContent from '../../components/orderContent.vue';

	export default {
		components: {
			tips,
			bottomView,
			orderContent
		},
		data() {
			return {
        previewUrl: '',
				checked: false,
				systemNotice: [],
				choosePaper: false,
				fileInfo: {},
				imgHost: this.$api.yuming,
				// 选项数据
				paperList: [],
				colourList: [],
				brandList: [],
				coverColors: [],
				reduceList: [],
				printRangeList: [], // 起始页
				paperDes: '',
				colourDes: '',
				reductionDes: '',
				brandDes: '',
				popShow: false, // 起始页弹窗
				columns: [{
					values: ['1', '2'],
					defaultIndex: 1
				}, {
					values: ['1', '2'],
					defaultIndex: 2
				}],
				singleList: [{
					name: '单面',
					id: 0
				}, {
					name: '双面',
					id: 1
				}],
				// 装订方式
				typeList: ['不装钉', '订书钉', '圈装', '胶装'],
				isPrintsRange: false, // 是否显示打印范围
				// 封面内容
				coverTips: false, // 切换封面提示语
				coverList: ['文字封面', '首页为封面', '上传封面', '纯色封面'],
				coverIndex: 3, // 选中封面index,默认纯色
				coverChooseIndex: 3, // 记录选中封面index,用于弹窗确定之后赋值给coverIndex
				textUrl: '', // 文字封面图片地址
				coverInfo: {}, // 文字封面内容，编辑的时候用
				imgsUrl: '', // 图片封面地址
				imgsCoverInfo: {}, // 上传图片文件内容，编辑的时候用
				// 价格
				allPrice: 0, // 总价
				onePrice_: 0, // 单价
				priceInfo: {},
				onePriceInfo: {},
				colourPriceInfo: {},
				brandPriceInfo: {},
				priceListNum: [], // 设定的价格
				// 纸张数
				choosePage: 0, // 选中的张数
				printPage: 0, // 打印张数(单面 = 选中张数；双面 = 选中张数/2)
				infoPage: 0, // 总共多少张纸
				// 数据
				bindingName: '', // 皮纹纸 铜版纸
				random: 0, // 颜色随机数index
				coverColorIndex: null, // 最终选中的颜色index
				pageTurningType: '', //方向:0=全是横向,1=全是纵向,2=横纵都有
				// 获取价格
				priceData: {
					brand_id: '', // 纸型id
					paper_id: '', // 纸张id
					colour_id: '', // 打印方式
					single_double: '', // 单双面
					price: '', // 价格
				},
				// 胶装单册
				jiaozhuangShow: false,
				// 订书钉和圈装
				dingshudingShow: false,
				// 几合一就是除以几
				chuyi: 1,
				// 解决方案路径
				schemeUrl: this.$api.yuming + '/uploads/mini/jjfa.docx',
				schemeUrl2: this.$api.yuming + '/uploads/mini/jjfa2.docx',
				//
				yuming: this.$api.yuming,
				// 复制一份
				copyShow: false,
				copy1Show: false,
				// 先预览
				lookShow: false,
				lookType: '',
				isLook: false,
				// 防连点
				isBtn: true, // 是否可以点击
				// 范围
				dsdMaxNum: 60, // 订书钉最大75张纸
				qzMaxNum: 120,
				jzMaxNum: 300,
				// 文件方向
				infoTurning: -1,
				// 请求数据
				formData: {
					id: '',
					paper: '',
					single_double: -1,
					binding_type: '',
					film_covering: '',
					cover_type: '',
					cover_image: '',
					reduction_printing: '',
					print_range: '',
					num: 1,
					colour: '',
					color: '',
					price: '',
					brand: '',
					page_turning: '',
				},
			}
		},
		onLoad(e) {
      this.$http.post(this.$api.image_info).then(res => {
        this.previewUrl = res.data?.rendering || '';
      })
			this.getNotice();
			let self = this;
			this.fileInfo = JSON.parse(decodeURIComponent(e.item)); // 文件信息
			this.formData.num = this.fileInfo.num; // 数量
			this.formData.id = this.fileInfo.id;

			let arr_ = this.fileInfo.name.split('.');
			this.lookType = arr_[arr_.length - 1];

			let p_ = Number(self.fileInfo.page);
			let arry = [];
			for (let i = 1; i <= p_; i++) {
				arry.push(i);
			}
			this.columns = [{
				values: arry,
				defaultIndex: 1
			}, {
				values: arry,
				defaultIndex: 2
			}]; // 起始页数据
			this.printRangeList.push('1-' + self.fileInfo.page);
			this.formData.print_range = this.printRangeList[0];

			this.choosePage = this.fileInfo.page;
			this.printPage = this.fileInfo.page;
			this.infoPage = this.fileInfo.page;

			this.formData.page_turning = this.fileInfo.type == 0 ? '横向翻页' : this.fileInfo.type == 1 ? '竖向翻页' : '';
			this.pageTurningType = this.fileInfo.type;

			this.formData.film_covering = '不覆膜';

			this.getPaper(); // 纸型列表
			this.getColour(); // 色彩列表
			this.getBrand(); // 纸张列表
			this.getReduce(); // 缩印列表
			this.getColor(); // 封面颜色列表
			this.getPriceInfo(); // 获取价格 

			if (this.fileInfo.paper) {
				setTimeout(() => {
					this.getDetail();
				}, 0)
			}

			// 初始化数据
			this.formData.binding_type = '不装钉';
			this.isPrintsRange = false;

			this.getDirection();
		},
		onShow() {
			if (uni.getStorageSync('coverTextData')) {
				this.textUrl = uni.getStorageSync('coverTextData').url;
				this.coverInfo = uni.getStorageSync('coverTextData');
				uni.removeStorageSync('coverTextData');
			}

			if (uni.getStorageSync('coverImgData')) {
				this.imgsUrl = uni.getStorageSync('coverImgData').url;
				this.imgsCoverInfo = uni.getStorageSync('coverImgData');
				uni.removeStorageSync('coverImgData');
			}
		},
		methods: {
      // 查看效果图
      handlePreview() {
        uni.previewImage({
          urls: [this.previewUrl]
        });
      },
			// 获取公告
			getNotice() {
				this.$http.get(this.$api.systemNotice).then((res) => {
					if (res.system_notice.length === 0) {
						res.system_notice = ['暂无公告~']
					}
					this.systemNotice = res.system_notice;
				})
			},
			// 获取文件方向
			getDirection() {
				this.$http.post(this.$api.direction, {
					id: this.fileInfo.id
				}).then((res) => {
					if (res.data.first === 0 && res.data.shu === 0) {
						this.infoTurning = 0 // '全部横向'
					} else if (res.data.first === 1 && res.data.heng === 0) {
						this.infoTurning = 1 // '全部竖向'
					} else if (res.data.first === 0 && res.data.heng === 0) {
						this.infoTurning = 2 // '首页横向其他竖向'
					} else {
						this.infoTurning = 3 // '横竖都有'
					}
				})
			},
			getDetail() {
				if (this.fileInfo.paper) {
					this.formData = {
						id: this.fileInfo.id,
						paper: this.fileInfo.paper,
						single_double: this.fileInfo.single_double,
						binding_type: this.fileInfo.binding_type,
						film_covering: this.fileInfo.film_covering ? this.fileInfo.film_covering : '不覆膜',
						cover_type: this.fileInfo.cover_type,
						cover_image: this.fileInfo.cover_image,
						reduction_printing: this.fileInfo.reduction_printing,
						print_range: this.fileInfo.print_range,
						num: this.fileInfo.num,
						colour: this.fileInfo.colour,
						color: this.fileInfo.color,
						price: '',
						brand: this.fileInfo.brand
					}
					if (this.fileInfo.page_turning) this.formData.page_turning = this.fileInfo.page_turning; // 横竖方向
					if (!this.fileInfo.page_turning) this.formData.page_turning = this.fileInfo.type == 0 ? '横向翻页' : this
						.fileInfo.type == 1 ? '竖向翻页' : '';

					if (this.printRangeList[0] != this.fileInfo.print_range) this.printRangeList.push(this.fileInfo
						.print_range);

					this.onePrice_ = Number(this.fileInfo.price);
					this.allPrice = this.onePrice_ * Number(this.fileInfo.num);

					let a_ = this.fileInfo.print_range.split('-');
					this.choosePage = (Number(a_[1]) - Number(a_[0])) + 1;
					this.printPage = this.formData.single_double == 1 ? Math.ceil(this.choosePage / 2) : this.choosePage;
					this.infoPage = this.formData.single_double == 1 ? Math.ceil(this.fileInfo.page / 2) : this.fileInfo
						.page;
					this.priceData.single_double = this.fileInfo.single_double;

					this.coverList.forEach((n, k) => {
						if (this.fileInfo.cover_type == n) {
							this.coverIndex = k;
						}
					})

					if (this.formData.binding_type.substring(0, 2) == '胶装') {
						this.bindingName = this.formData.binding_type.substring(2, 5);
						this.formData.binding_type = '胶装';
					}

					if (this.coverIndex == 0) { // 文字封面
						this.textUrl = this.fileInfo.cover_image;
						this.coverInfo = {};
					} else if (this.coverIndex == 2) { // 图片封面
						this.imgsUrl = this.fileInfo.cover_image;
						this.imgsCoverInfo = {};
					}

					if (this.formData.binding_type === '不装钉') {
						this.isPrintsRange = false;
					} else if (this.formData.binding_type === '订书钉') {
						// && this.infoPage > this.dsdMaxNum
						this.isPrintsRange = false;
					} else if (this.formData.binding_type === '圈装' && this.infoPage < this.qzMaxNum) {
						this.isPrintsRange = false;
					} else if (this.formData.binding_type === '胶装' && this.infoPage < this.jzMaxNum) {
						this.isPrintsRange = false;
					} else {
						this.isPrintsRange = true;
					}
				}
			},
			getPaper() {
				this.$http.post(this.$api.paper).then(res => {
					this.paperList = res.data;
					if (this.fileInfo.paper) {
						res.data.forEach((n) => {
							if (n.name == this.fileInfo.paper) {
								this.onePriceInfo = n;
								this.priceData.paper_id = n.id;
								this.paperDes = n.remark;
							}
						})
					}
				})
			},
			getColour() {
				this.$http.post(this.$api.colour).then(res => {
					this.colourList = res.data;
					if (this.fileInfo.colour) {
						res.data.forEach((n) => {
							if (n.name == this.fileInfo.colour) {
								this.colourPriceInfo = n;
								this.priceData.colour_id = n.id;
								this.colourDes = n.remark;
							}
						})
					}
				})
			},
			getBrand() {
				this.$http.post(this.$api.brand).then(res => {
					this.brandList = res.data;
					if (this.fileInfo.brand) {
						res.data.forEach((n) => {
							if (n.name == this.fileInfo.brand) {
								this.brandPriceInfo = n;
								this.brandDes = n.remark;
							}
						})
					}

					setTimeout(() => {
						if (!this.fileInfo.brand) {
							this.priceData.brand_id = res.data[0].id;
							this.formData.brand = res.data[0].name;
							this.brandDes = res.data[0].remark;
							this.getSetPrice();
						} else {
							this.brandList.forEach((n, k) => {
								if (n.name == this.formData.brand) {
									this.priceData.brand_id = n.id;
									this.getSetPrice(true);
								}
							})
						}
					}, 0)
				})
			},
			getColor() {
				this.$http.post(this.$api.color).then(res => {
					this.coverColors = res.data;

					res.data.forEach((n, k) => {
						if (n.name == '随机颜色') {
							this.random = k;
						}

						if (!this.fileInfo.color) {
							this.coverColorIndex = this.random;
						} else {
							if (n.name == this.fileInfo.color) {
								this.coverColorIndex = k;
							}
						}
					})

					// this.random = RandomNumBoth(0, this.coverColors.length - 1); // 随机index
					// this.coverColorIndex = this.random;
					this.formData.color = this.coverColors[this.coverColorIndex].name;

					function RandomNumBoth(Min, Max) {
						var Range = Max - Min;
						var Rand = Math.random();
						var num = Min + Math.round(Rand * Range); //四舍五入
						return num;
					}
				})
			},
			getReduce() {
				this.$http.post(this.$api.reduce).then(res => {
					this.reduceList = res.data;

					let r_i = 0;
					this.reduceList.forEach((n, k) => {
						if (n.name == '不缩印') {
							r_i = k
						}
					})

					this.formData.reduction_printing = this.reduceList[r_i].name;
					this.reductionDes = this.reduceList[r_i].remark;
				})
			},
			getSetPrice(e) {
				this.$http.post(this.$api.prints, {
					brand_id: this.priceData.brand_id
				}).then(res => {
					this.priceListNum = res.data;
					let l_ = res.data;
					let paper_ = [];
					let single_ = [];
					let colour_ = [];

					this.paperList.forEach((n, k) => {
						n.isChoose = undefined;
					})
					this.singleList.forEach((n, k) => {
						n.isChoose = undefined;
					})
					this.colourList.forEach((n, k) => {
						n.isChoose = undefined;
					})

					console.log(l_)

					l_.forEach((n, k) => {
						// paper
						this.paperList.forEach((pn, pk) => {
							if (pn.id == n.paper_id) {
								pn.isChoose = true;
								paper_.push(pn);
							}
						})
						// 单双面
						this.singleList.forEach((sn, sk) => {
							if (sn.id == n.single_double) {
								sn.isChoose = true;
								single_.push(sn);
							}
						})
						// 色彩（打印方式）
						this.colourList.forEach((cn, ck) => {
							if (cn.id == n.colour_id) {
								cn.isChoose = true;
								colour_.push(cn);
							}
						})
					})

					if (!e) { // 初始化
						// 纸型 
						paper_ = Array.from(new Set(paper_)); // 去重
						let p_i = 0;

						paper_.forEach((n, k) => {
							if (n.name == 'A4') {
								p_i = k
							}
						})

						this.formData.paper = paper_[p_i].name;
						this.priceData.paper_id = paper_[p_i].id;
						this.paperDes = paper_[p_i].remark;

						// 单双面
						single_ = Array.from(new Set(single_));
						let s_i = 0;

						single_.forEach((n, k) => {
							if (n.name == '双面') {
								s_i = k
							}
						})

						this.formData.single_double = single_[s_i].id;
						this.priceData.single_double = single_[s_i].id;
						if (this.formData.single_double == 0) {
							this.printPage = this.choosePage;
							this.infoPage = this.fileInfo.page;
						}
						if (this.formData.single_double == 1) {
							this.printPage = Math.ceil(this.choosePage / 2);
							this.infoPage = Math.ceil(this.fileInfo.page / 2);
						}

						// 打印方式
						colour_ = Array.from(new Set(colour_)); // 去重
						let c_i = 0;

						colour_.forEach((n, k) => {
							if (n.name == '黑白激光') {
								c_i = k
							}
						})

						this.formData.colour = colour_[c_i].name;
						this.priceData.colour_id = colour_[c_i].id;
						this.colourDes = colour_[c_i].remark;
					}

					this.getPrice();
				})
			},
			getPaperChoose(item) {
				if (item.isChoose) {
					this.formData.paper = item.name;
					this.priceData.paper_id = item.id;
					this.paperDes = item.remark;

					let single_ = [];
					let colour_ = [];

					let arr = [];
					this.priceListNum.forEach((n, k) => {
						if (n.brand_id == this.priceData.brand_id && n.paper_id == this.priceData.paper_id) {
							arr.push(n)
						}
					})

					this.singleList.forEach((n, k) => {
						n.isChoose = undefined;
					})
					this.colourList.forEach((n, k) => {
						n.isChoose = undefined;
					})

					arr.forEach((n, k) => {
						// 单双面
						this.singleList.forEach((sn, sk) => {
							if (sn.id == n.single_double) {
								sn.isChoose = true;
								single_.push(sn);
							}
						})
						// 色彩（打印方式）
						this.colourList.forEach((cn, ck) => {
							if (cn.id == n.colour_id) {
								cn.isChoose = true;
								colour_.push(cn);
							}
						})
					})

					single_ = Array.from(new Set(single_));
					let s_ = false;
					single_.forEach((n, k) => {
						if (n.id == this.priceData.single_double) {
							s_ = true;
						}
					})
					if (!s_) {
						this.formData.single_double = single_[0].id;
						this.priceData.single_double = single_[0].id;
						if (this.formData.single_double == 0) {
							this.printPage = this.choosePage;
							this.infoPage = this.fileInfo.page;
						}
						if (this.formData.single_double == 1) {
							this.printPage = Math.ceil(this.choosePage / 2);
							this.infoPage = Math.ceil(this.fileInfo.page / 2);
						}
					}

					colour_ = Array.from(new Set(colour_)); // 去重
					let c_ = false;
					colour_.forEach((n, k) => {
						if (n.id == this.priceData.colour_id) {
							c_ = true;
						}
					})
					if (!c_) {
						this.formData.colour = colour_[0].name;
						this.priceData.colour_id = colour_[0].id;
						this.colourDes = colour_[0].remark;
					}

					if (this.formData.paper == 'B5' && this.formData.binding_type === '圈装') {
						this.formData.binding_type = '不装钉';
						this.isPrintsRange = false;
					}

					if (this.formData.paper == 'B5' && this.bindingName == '铜版纸') {
						this.bindingName = '';
					}

					if (this.formData.paper == 'B5' && this.formData.binding_type === '胶装') {
						// b5如果选择胶装的话只能选纯色封面，其他三个封面都不能选
						this.coverIndex = 3;
					}

					if (this.formData.paper == 'A3' &&
						(this.formData.binding_type === '圈装' || this.formData.binding_type === '胶装')) {
						this.formData.binding_type = '不装钉';
						this.isPrintsRange = false;
					}

					this.getPrice();
				}
			},
			getPageTurning(e) {
				this.formData.page_turning = e;

				if (e === '横向翻页') {
					if (this.bindingName === '铜版纸') {
						this.bindingName = '皮纹纸';
					}
					if (this.coverIndex == 0 || this.coverIndex == 1 || this.coverIndex == 2) {
						this.coverIndex = 3;
					}
				}
			},
			getSingle(item) {
				if (item.isChoose) {
					if (item.id == 0) {
						this.printPage = this.choosePage;
						this.infoPage = this.fileInfo.page;
					} else {
						if (this.choosePage == 1) return getApp().getMsg('文件只有1页，不支持双面打印');
						if (this.choosePage == 2 && (this.formData.binding_type == '订书钉' || this.formData.binding_type ==
								'胶装')) {
							return getApp().getMsg('2页文件选择双面打印无需装订');
						}
						this.printPage = Math.ceil(this.choosePage / 2);
						this.infoPage = Math.ceil(this.fileInfo.page / 2);
					}

					this.formData.single_double = item.id;
					this.priceData.single_double = item.id;

					let paper_ = [];
					let colour_ = [];

					let arr = [];
					this.priceListNum.forEach((n, k) => {
						if (n.brand_id == this.priceData.brand_id && n.single_double == this.priceData
							.single_double) {
							arr.push(n)
						}
					})

					this.paperList.forEach((n, k) => {
						n.isChoose = undefined;
					})
					this.colourList.forEach((n, k) => {
						n.isChoose = undefined;
					})

					arr.forEach((n, k) => {
						// paper
						this.paperList.forEach((pn, pk) => {
							if (pn.id == n.paper_id) {
								pn.isChoose = true;
								paper_.push(pn);
							}
						})
						// 色彩（打印方式）
						this.colourList.forEach((cn, ck) => {
							if (cn.id == n.colour_id) {
								cn.isChoose = true;
								colour_.push(cn);
							}
						})
					})

					paper_ = Array.from(new Set(paper_)); // 去重
					let p_ = false;
					paper_.forEach((n, k) => {
						if (n.id == this.priceData.paper_id) {
							p_ = true;
						}
					})
					if (!p_) {
						this.formData.paper = paper_[0].name;
						this.priceData.paper_id = paper_[0].id;
						this.paperDes = paper_[0].remark;
					}

					colour_ = Array.from(new Set(colour_)); // 去重
					let c_ = false;
					colour_.forEach((n, k) => {
						if (n.id == this.priceData.colour_id) {
							c_ = true;
						}
					})
					if (!c_) {
						this.formData.colour = colour_[0].name;
						this.priceData.colour_id = colour_[0].id;
						this.colourDes = colour_[0].remark;
					}

					if (this.formData.binding_type === '不装钉') {
						this.formData.print_range = this.printRangeList[0];
						this.isPrintsRange = false;
						this.getPages(this.printRangeList[0]);
					} else if (this.formData.binding_type === '订书钉') {
						// && this.infoPage > this.dsdMaxNum
						this.formData.print_range = this.printRangeList[0];
						this.isPrintsRange = false;
						this.formData.binding_type = '不装钉';
						this.getPages(this.printRangeList[0]);
					} else if (this.formData.binding_type === '圈装' && this.infoPage < this.qzMaxNum) {
						this.formData.print_range = this.printRangeList[0];
						this.isPrintsRange = false;
						this.getPages(this.printRangeList[0]);
					} else if (this.formData.binding_type === '胶装' && this.infoPage < this.jzMaxNum) {
						this.formData.print_range = this.printRangeList[0];
						this.isPrintsRange = false;
						this.getPages(this.printRangeList[0]);
					} else {
						this.isPrintsRange = true;
						this.getPrice();
					}
				}
			},
			getColourChoose(item) {
				if (item.isChoose) {
					this.formData.colour = item.name;
					this.priceData.colour_id = item.id;
					this.colourDes = item.remark;

					let paper_ = [];
					let single_ = [];

					let arr = [];
					this.priceListNum.forEach((n, k) => {
						if (n.brand_id == this.priceData.brand_id && n.colour_id == this.priceData.colour_id) {
							arr.push(n)
						}
					})

					this.paperList.forEach((n, k) => {
						n.isChoose = undefined;
					})
					this.singleList.forEach((n, k) => {
						n.isChoose = undefined;
					})

					arr.forEach((n, k) => {
						// paper
						this.paperList.forEach((pn, pk) => {
							if (pn.id == n.paper_id) {
								pn.isChoose = true;
								paper_.push(pn);
							}
						})
						// 单双面
						this.singleList.forEach((sn, sk) => {
							if (sn.id == n.single_double) {
								sn.isChoose = true;
								single_.push(sn);
							}
						})
					})

					paper_ = Array.from(new Set(paper_)); // 去重
					let p_ = false;
					paper_.forEach((n, k) => {
						if (n.id == this.priceData.paper_id) {
							p_ = true;
						}
					})
					if (!p_) {
						this.formData.paper = paper_[0].name;
						this.priceData.paper_id = paper_[0].id;
						this.paperDes = paper_[0].remark;
					}

					single_ = Array.from(new Set(single_));
					let s_ = false;
					single_.forEach((n, k) => {
						if (n.id == this.priceData.single_double) {
							s_ = true;
						}
					})
					if (!s_) {
						this.formData.single_double = single_[0].id;
						this.priceData.single_double = single_[0].id;
						if (this.formData.single_double == 0) {
							this.printPage = this.choosePage;
							this.infoPage = this.fileInfo.page;
						}
						if (this.formData.single_double == 1) {
							this.printPage = Math.ceil(this.choosePage / 2);
							this.infoPage = Math.ceil(this.fileInfo.page / 2);
						}
					}

					this.getPrice();

					if (item.name === '彩色喷墨' && this.formData.brand === '70g普通型') {
						this.choosePaper = true;
					}
				}
			},
			getBrandChoose(item, e) {
				this.formData.brand = item.name;
				this.priceData.brand_id = item.id;
				this.brandDes = item.remark;
				this.getSetPrice(e);
			},
			// 选护眼纸
			getPaperSubmit() {
				this.choosePaper = false;
				this.brandList.forEach((n, k) => {
					if (n.name === '80g复印纸') {
						this.getBrandChoose(n, true);
					}
				})
			},
			// 装订方式
			getTypeChoose(item) {
				console.log('item:', item)
				if (this.formData.paper === 'B5' && item === '圈装') {
					return
				}

				if (this.formData.paper === 'A3' && (item === '圈装' || item === '胶装')) {
					return
				}

				if (item === '订书钉' && this.infoPage > this.dsdMaxNum) {
					return getApp().getMsg('超过最大可装订页数');
				}

				if (this.choosePage == 1 && item !== '不装钉') {
					return getApp().getMsg('文件只有1页，不支持订书钉/圈装/胶装');
				}

				if (this.choosePage > 10 && item == '不装钉') {
					getApp().getMsg('不装订可能影响使用体验，建议选择其他装订方式');
				}

				if (this.choosePage == 2 && this.formData.single_double == 1 && (item == '订书钉' || item == '胶装')) {
					return getApp().getMsg('2页文件选择双面打印无需装订');
				}

				// if (item === '订书钉' && this.formData.reduction_printing === '二合一') return getApp().getMsg('不可选');
				// if (item === '圈装' && this.formData.reduction_printing === '二合一') return getApp().getMsg('不可选');
				if (item === '胶装') {
					this.bindingName = '皮纹纸';
					this.coverIndex = 3;
				}

				this.formData.binding_type = item;

				if (item === '不装钉') {
					this.formData.print_range = this.printRangeList[0];
					this.isPrintsRange = false;
					this.getPages(this.printRangeList[0]);
				} else if (item === '订书钉') {
					// && this.infoPage > this.dsdMaxNum
					this.formData.print_range = this.printRangeList[0];
					this.isPrintsRange = false;
					this.getPages(this.printRangeList[0]);
				} else if (item === '圈装' && this.infoPage < this.qzMaxNum) {
					this.formData.print_range = this.printRangeList[0];
					this.isPrintsRange = false;
					this.getPages(this.printRangeList[0]);
				} else if (item === '胶装' && this.infoPage < this.jzMaxNum) {
					this.formData.print_range = this.printRangeList[0];
					this.isPrintsRange = false;
					this.getPages(this.printRangeList[0]);
				} else {
					this.isPrintsRange = true;
					this.getPrice();
				}

				if (this.formData.binding_type === '胶装' && this.printPage > this.jzMaxNum) {
					this.jiaozhuangShow = true;
				}

				if (this.formData.binding_type === '圈装' && this.printPage > this.qzMaxNum) {
					this.dingshudingShow = true;
				}

				if (this.formData.binding_type === '订书钉' && this.infoPage > this.dsdMaxNum) {
					this.dingshudingShow = true;
				}

				this.getPrice();
			},
			//
			getReduceCompent() {
				this.formData.reduction_printing = this.reduceList[0].name;
				this.reductionDes = this.reduceList[0].remark;
				this.chuyi = 1;
				this.getPrice();
			},
			// 胶装
			getBindingType(i) {
				if (this.formData.paper == 'B5' && i == '铜版纸') return getApp().getMsg('B5不能选铜版纸');
				if (this.getDirectionStr() === '横向翻页' && i == '铜版纸') return getApp().getMsg('不能选铜版纸');

				this.bindingName = i;
				this.getPrice();
			},
			getCoverColor(i) {
				this.coverColorIndex = i;
				this.formData.color = this.coverColors[this.coverColorIndex].name;
				this.getPrice();
			},
			getChangeType(i) {
				// if (this.pageTurningType == 0) return getApp().getMsg('横向文档只能选择纯色哦');
				if (this.formData.paper == 'B5') return getApp().getMsg('B5只能选择纯色哦');
				if (this.infoTurning != 1 && this.infoTurning != 2 && i != 3) return getApp().getMsg('只能选择纯色哦');
				if (this.formData.reduction_printing === '二合一' && i != 3) return getApp().getMsg('只能选择纯色哦');

				this.coverChooseIndex = i;

				if (this.coverIndex == 3) {
					this.coverIndex = i;
					this.getPrice();
					return
				}

				if (i == this.coverIndex) {
					return;
				}

				if (this.coverIndex == 0 && this.textUrl && i != this.coverIndex) this.coverTips = true;
				if (this.coverIndex == 0 && !this.textUrl && i != this.coverIndex) this.coverIndex = i;
				if (this.coverIndex == 1 && i != this.coverIndex) this.coverTips = true;
				if (this.coverIndex == 2 && this.imgsUrl && i != this.coverIndex) this.coverTips = true;
				if (this.coverIndex == 2 && !this.imgsUrl && i != this.coverIndex) this.coverIndex = i;

				this.getPrice();
			},
			getDialogConfirm() {
				// 文字 
				if (this.coverIndex == 0) {
					this.textUrl = '';
					this.coverInfo = {};
				}
				// 上传
				if (this.coverIndex == 2) {
					this.imgsUrl = '';
					this.imgsCoverInfo = {};
				}

				this.coverTips = false;
				this.coverIndex = this.coverChooseIndex;

				this.getPrice();
			},
			// 胶装结束
			getReduceChoose(item) {
				if (this.fileInfo.password == 1 && item.num == 2) {
					// 有密码，不给选
					getApp().getMsg('文档有密码，不可选择')
					return
				}
				if (this.fileInfo.type == 2 && item.num == 2) {
					// 文档有横向和竖向，不给选择
					getApp().getMsg('不可选择')
					return
				}

				this.formData.reduction_printing = item.name;
				this.reductionDes = item.remark;
				this.chuyi = item.num ? item.num : 1;

				if (this.formData.binding_type === '不装钉') {
					this.getPrice();
				}

				if (this.formData.binding_type === '订书钉') {
					if (item.num == 0) {
						this.getPrice();
					} else if (item.num == 2) {
						// this.formData.binding_type = '不装钉';
						this.getPrice();
					}
				}

				if (this.formData.binding_type === '圈装') {
					if (item.num == 0) {
						this.getPrice();
					} else if (item.num == 2) {
						// this.formData.binding_type = '不装钉';
						this.getPrice();
					}
				}

				if (this.formData.binding_type === '胶装') {
					if (this.getDirectionStr(false, item.name) === '横向翻页' && this.bindingName !== '皮纹纸') {
						this.bindingName = '皮纹纸';
					}
					if (this.getDirectionStr(false, item.name) === '横向翻页' && (this.coverIndex == 0 || this.coverIndex ==
							1 || this.coverIndex ==
							2)) {
						this.coverIndex = 3;
					}
					if (item.num == 2) {
						this.coverIndex = 3;
					}
					this.getPrice();
				}

				// 不装钉 胶装 + 皮纹纸 + 纯色 才能选择二合一
			},
			getPageConfirm(e) {
				let s_ = true;
				this.popShow = false;
				if (Number(e.detail.value[1]) < Number(e.detail.value[0])) return getApp().getMsg('开始页不能大于结束页');
				if (this.printRangeList.length > 0) {
					this.printRangeList.forEach((n) => {
						if (n == (e.detail.value[0] + '-' + e.detail.value[1])) {
							s_ = false
						}
					})
				}
				if (s_) {
					this.printRangeList.push(e.detail.value[0] + '-' + e.detail.value[1]);
				} else {
					getApp().getMsg('请勿重复添加');
				}
			},
			getPages(item, e) {
				if (this.formData.binding_type === '不装钉' && e) {
					return getApp().getMsg('不装钉，不可以选择打印范围')
				}
				if (this.formData.binding_type === '订书钉' && this.infoPage > this.dsdMaxNum && e) {
					return getApp().getMsg('订书钉超过' + this.dsdMaxNum + '张，不可以选择打印范围')
				}
				if (this.formData.binding_type === '圈装' && this.infoPage < this.qzMaxNum && e) {
					return getApp().getMsg('圈装不超过' + this.qzMaxNum + '张，不可以选择打印范围')
				}
				if (this.formData.binding_type === '胶装' && this.infoPage < this.jzMaxNum && e) {
					return getApp().getMsg('胶装不超过' + this.jzMaxNum + '张，不可以选择打印范围')
				}
				let a_ = item.split('-');
				this.formData.print_range = item;
				this.choosePage = (Number(a_[1]) - Number(a_[0])) + 1;
				this.printPage = this.formData.single_double == 1 ? Math.ceil(this.choosePage / 2) : this.choosePage;

				if (this.choosePage == 1) {
					this.formData.single_double = 0 // 单面
					this.formData.binding_type = '不装钉';
					this.isPrintsRange = false;
				} else if (this.choosePage == 2 && this.formData.single_double == 1 && (this.formData.binding_type ==
						'订书钉' || this.formData.binding_type == '胶装')) {
					this.formData.binding_type = '不装钉';
					this.isPrintsRange = false;
				}

				this.getPrice();
			},
			getDel(item, index) { // 删除
				if (this.formData.print_range != item) {
					this.printRangeList.splice(index, 1);
				} else {
					this.printRangeList.splice(index, 1);
					this.formData.print_range = this.printRangeList[0];
					this.choosePage = this.fileInfo.page;
					this.printPage = this.fileInfo.page;

					if (this.choosePage == 1) {
						this.formData.single_double = 0 // 单面
						this.formData.binding_type = '不装钉';
						this.this.isPrintsRange = false;
					} else if (this.choosePage == 2 && this.formData.single_double == 1 && (this.formData.binding_type ==
							'订书钉' || this.formData.binding_type == '胶装')) {
						this.formData.binding_type = '不装钉';
						this.isPrintsRange = false;
					}

					this.getPrice();
				}
			},
			getChooseNum(index) {
				let n_ = this.formData.num;

				if (index == 0 && n_ == 1) return;

				if (index == 0 && n_ != 1) {
					n_--;
				}
				if (index == 1) {
					n_++;
				}

				this.formData.num = n_;
				this.getPrice();
			},
			getNumChange(e) {
				if (e.detail.value === '' || e.detail.value === '0') {
					this.formData.num = 1;
				} else {
					this.formData.num = Number(e.detail.value);
				}
				this.getPrice();
			},
			// 获取价格
			getPriceInfo() {
				this.$http.post(this.$api.price).then(res => {
					this.priceInfo = res.data;
				})
			},
			// 算价格
			getPrice() {
				let oneP_1 = 0; // 后台设置价格
				this.priceListNum.forEach((n, k) => {
					if (n.brand_id == this.priceData.brand_id &&
						n.paper_id == this.priceData.paper_id &&
						n.colour_id == this.priceData.colour_id &&
						n.single_double == this.priceData.single_double) {
						oneP_1 = Number(n.price)
					}
				})

				let oneP_2 = 0; // 装订方式价格
				if (this.formData.binding_type == '不装订') oneP_2 = 0;
				if (this.formData.binding_type == '订书钉') oneP_2 = Number(this.priceInfo.staple_price);
				if (this.formData.binding_type == '圈装') oneP_2 = Number(this.priceInfo.ring_mounting_price);

				let oneP_3 = 0; // 封面类型
				oneP_3 = this.bindingName === '皮纹纸' ? Number(this.priceInfo.paper_cover_price) : this.bindingName ===
					'铜版纸' ? Number(this.priceInfo.art_paper_price) : 0;

				let oneP_4 = 0; // 封面颜色
				if (this.formData.binding_type == '胶装' && this.bindingName === '皮纹纸') {
					if (this.coverColorIndex == this.random) {
						oneP_4 = Number(this.priceInfo.random_color_price); // 系统随机选中的颜色
					} else {
						oneP_4 = Number(this.priceInfo.select_color_price); // 自己选中的颜色
					}
				} else {
					oneP_4 = 0;
				}

				let oneP_5 = 0; // 封面内容
				if (this.formData.binding_type == '胶装') {
					if (this.coverIndex == 3) {
						oneP_5 = 0
					} else {
						oneP_5 = Number(this.priceInfo.cover_price)
					}
				}

				let oneP_6 = 0; // 覆膜
				if (this.formData.binding_type == '胶装' && this.bindingName === '铜版纸') {
					if (this.formData.film_covering === '覆膜') {
						oneP_6 = Number(this.priceInfo.film_covering);
					} else {
						oneP_6 = 0;
					}
				} else {
					oneP_6 = 0;
				}

				if (this.formData.binding_type !== '胶装') {
					oneP_3 = 0;
				}

				let one_ = 0; // 一份价格
				one_ = (oneP_1 * Math.ceil(this.printPage / this.chuyi)) + oneP_2 + oneP_3 + oneP_4 + oneP_5 + oneP_6;

				console.log(oneP_1)
				console.log(oneP_2)
				console.log(oneP_3)
				console.log(oneP_4)
				console.log(oneP_5)

				this.onePrice_ = one_.toFixed(2);
				this.allPrice = (one_ * this.formData.num).toFixed(2);
			},
			// 算价格
			// getPrice() {
			// 	// 纸型 = 单张价格 * 张数 (注意：列表算运费，克数)
			// 	let oneP1 = Number(this.onePriceInfo.price) * this.printPage || 0;
			// 	// 单面 = 单面价格 * 张数   双面 = 双面价格 * 张数
			// 	let oneP2 = 0;
			// 	if (this.formData.single_double == 0) { // 单面
			// 		oneP2 = Number(this.priceInfo.one_price) * this.printPage;
			// 	} else if (this.formData.single_double == 1) { // 双面
			// 		oneP2 = Number(this.priceInfo.two_price) * this.printPage;
			// 	}
			// 	// 色彩 = 色彩价格 * 张数
			// 	let oneP3 = Number(this.colourPriceInfo.price) * this.printPage || 0;
			// 	// 纸张 = 单张价格 * 张数
			// 	let oneP5 = Number(this.brandPriceInfo.price) * this.printPage || 0;
			// 	// 装订方式
			// 	let oneP4 = 0;
			// 	if (this.formData.binding_type == '不装订') oneP4 = 0;
			// 	if (this.formData.binding_type == '订书钉') oneP4 = Number(this.priceInfo.staple_price);
			// 	if (this.formData.binding_type == '圈装') oneP4 = Number(this.priceInfo.ring_mounting_price);
			// 	// 封面类型
			// 	let oneP6 = 0;
			// 	oneP6 = this.bindingName === '皮纹纸' ? Number(this.priceInfo.paper_cover_price) : this.bindingName ===
			// 		'铜版纸' ? Number(this.priceInfo.art_paper_price) : 0;
			// 	// 封面颜色
			// 	let oneP7 = 0;
			// 	if (this.formData.binding_type == '胶装' && this.bindingName === '皮纹纸') {
			// 		if (this.coverColorIndex == this.random) {
			// 			oneP7 = Number(this.priceInfo.random_color_price); // 系统随机选中的颜色
			// 		} else {
			// 			oneP7 = Number(this.priceInfo.select_color_price); // 自己选中的颜色
			// 		}
			// 	} else {
			// 		oneP7 = 0;
			// 	}
			// 	// 封面价格
			// 	let oneP8 = 0;
			// 	if (this.coverIndex == 0 && this.textUrl) oneP8 = Number(this.priceInfo.cover_price);
			// 	if (this.coverIndex == 0 && !this.textUrl) oneP8 = 0;
			// 	if (this.coverIndex == 1) oneP8 = Number(this.priceInfo.cover_price);
			// 	if (this.coverIndex == 2 && this.imgsUrl) oneP8 = Number(this.priceInfo.cover_price);
			// 	if (this.coverIndex == 2 && !this.imgsUrl) oneP8 = 0;
			// 	if (this.coverIndex == 3) oneP8 = 0;

			// 	// 1份价格
			// 	let one_ = oneP1 + oneP2 + oneP3 + oneP4 + oneP5;
			// 	if (this.formData.binding_type === '胶装') {
			// 		one_ += oneP6;
			// 		one_ += oneP7;
			// 		one_ += oneP8;
			// 	}

			// 	this.onePrice_ = one_;
			// 	this.allPrice = one_ * this.formData.num;
			// },
			// 提交
			getSubmit() {
				let title_ = this.formData.binding_type;
				let self = this;
				if (!this.formData.paper) return getApp().getMsg('请设置纸型');
				// if (!this.formData.page_turning && this.pageTurningType == 2) return getApp().getMsg('请设置翻页方向');
				if (this.formData.single_double == -1) return getApp().getMsg('请设置单双面');
				if (!this.formData.colour) return getApp().getMsg('请设置打印方式');
				if (!this.formData.brand) return getApp().getMsg('请设置纸张');
				if (!this.formData.binding_type) return getApp().getMsg('请设置装订方式');
				if (this.formData.binding_type == '胶装') {
					if (!this.bindingName) return getApp().getMsg('请设置封面类型');
					if (this.bindingName == '皮纹纸' && !this.formData.color) return getApp().getMsg('请设置封面颜色');
					if (this.bindingName == '皮纹纸' && this.formData.color) title_ = this.formData.binding_type +
						this.bindingName;
					if (this.bindingName == '铜版纸' && !this.formData.film_covering) return getApp().getMsg(
						'请设置覆膜');
					if (this.bindingName == '铜版纸' && this.formData.film_covering) title_ = this.formData
						.binding_type + this.bindingName;
				} else {
					this.bindingName = '';
					this.formData.color = '';
					this.formData.film_covering = '';
					this.formData.cover_type = '';
					this.textUrl = '';
					this.imgsUrl = '';
				}
				if (!this.formData.reduction_printing) return getApp().getMsg('请设置缩印');

				this.formData.cover_type = this.formData.binding_type == '胶装' ? this.coverList[this.coverIndex] : '';
				this.formData.price = this.onePrice_;

				if (this.bindingName == '皮纹纸') this.formData.film_covering = '';
				if (this.bindingName == '铜版纸') this.formData.color = '';

				if (this.formData.cover_type === '文字封面' && !this.textUrl) return getApp().getMsg('请设置封面文字');
				if (this.formData.cover_type === '上传封面' && !this.imgsUrl) return getApp().getMsg('请上传封面图片');

				if (this.formData.binding_type === '胶装' && this.printPage > this.jzMaxNum) {
					this.jiaozhuangShow = true;
					return
				}

				if ((this.formData.binding_type === '订书钉' && this.printPage > this.dsdMaxNum) || (this.formData
						.binding_type === '圈装' && this.printPage > this.qzMaxNum)) {
					this.dingshudingShow = true;
					return
				}

				if (this.formData.cover_type === '文字封面') {
					this.formData.cover_image = this.textUrl;
				} else if (this.formData.cover_type === '上传封面') {
					this.formData.cover_image = this.imgsUrl;
				} else {
					this.formData.cover_image = '';
				}

				// if ((this.textUrl && this.textUrl.charAt(0) != '/') || (this.imgsUrl && this.imgsUrl.charAt(0) != '/'))
				if ((this.imgsUrl && this.imgsUrl.charAt(0) != '/')) {
					uni.uploadFile({
						url: self.$api.upload,
						filePath: self.textUrl ? self.textUrl : self.imgsUrl,
						name: 'file',
						header: {
							"Content-Type": "multipart/form-data",
						},
						formData: {},
						success: (uploadFileRes) => {
							let result = JSON.parse(uploadFileRes.data);

							if (result.code === 20000) {
								self.formData.cover_image = result.data.url;
								self.formData.binding_type = title_;
								self.getUrl();
							} else {
								getApp().getMsg(result.msg);
							}
						},
						fail(e) {
							console.log(e)
						}
					});

					return
				}

				this.formData.binding_type = title_;
				this.copy1Show = false;
				this.getUrl();
			},
			getUrl() {
				this.priceListNum.forEach((n, k) => {
					if (n.brand_id == this.priceData.brand_id &&
						n.paper_id == this.priceData.paper_id &&
						n.colour_id == this.priceData.colour_id &&
						n.single_double == this.priceData.single_double) {
						this.formData.commission_switch = n.commission_switch
					}
				})

				console.log(this.formData)

				if (!this.isBtn) return

				this.isBtn = false;

				this.$http.post(this.$api.cartEdit, this.formData).then(res => {
					getApp().getMsg('配置成功', 'success');
					getApp().getBack();
					uni.setStorageSync('set', true);

					setTimeout(() => {
						this.isBtn = true;
					}, 2000)
				})
				if (this.checked) {
					this.$http.post(this.$api.add_document, {
						cart_id: this.formData.id
					}).then(res => {
						console.log('加入文档库成功', res)
					})
				}
			},
			// 确认配置
			getSetData() {
				if (this.fileInfo.page === 0) {
					getApp().getMsg('该文件有密码获取不到页码，请解密后上传')
					return
				}

				if (this.lookType == 'pdf' || this.lookType == 'PDF') {
					this.getSubmit();
				} else {
					if (this.isLook) {
						this.getSubmit();
					} else {
						this.lookShow = true;
					}
				}
			},
			// 预览
			getClear() {
				let u_ = this.fileInfo.file;
				this.isLook = true;
				getApp().getSeeFile(u_);
			},
			getLookSubmit() {
				this.lookShow = false;
				this.getClear();
			},
			// 查看解决方案
			getLook() {
				this.jiaozhuangShow = false;
				let url_ = this.schemeUrl;
				getApp().getSeeFile(url_);
			},
			getLook2() {
				this.dingshudingShow = false;
				let url_ = this.schemeUrl2;
				getApp().getSeeFile(url_);
			},
			// 复制一份
			getDialogCopy() {
				let s_ = this.fileInfo.file.length - this.yuming.length;
				let fileUrl_ = this.fileInfo.file.slice(-s_);

				let arr_ = fileUrl_.split('.');
				let type = 0 // 0=pdf 1=word
				if (arr_[arr_.length - 1] === 'pdf' || arr_[arr_.length - 1] === 'PDF') {
					type = 0;
				} else {
					type = 1;
				}

				this.$http.post(this.$api.cartAdd, {
					file: fileUrl_,
					name: this.fileInfo.name,
					type: type
				}).then(res => {
					this.copyShow = false;
					this.copy1Show = true;
				})
			},
			// 上传封面图片
			getImgUp() {
				let self = this;
				uni.chooseImage({
					count: 1,
					sourceType: ['album', 'camera'], // 从相册，相机
					success: (res) => {
						self.imgsUrl = res.tempFilePaths[0];
					}
				})
			},
			// 判断文档方向
			getDirectionStr(e, n) {
				let a_ = e ? e : this.formData.page_turning; // 获取选择的方向
				let b_ = n ? n : this.formData.reduction_printing; // 获取缩印
				// 如果文档是竖向，选择二合一就是横向 ；如果文档是横向，选择二合一就是竖向
				if (a_ === '横向翻页' && b_ === '不缩印') {
					return '横向翻页';
				} else if (a_ === '横向翻页' && b_ === '二合一') {
					return '竖向翻页';
				} else if (a_ === '竖向翻页' && b_ === '不缩印') {
					return '竖向翻页';
				} else if (a_ === '竖向翻页' && b_ === '二合一') {
					return '横向翻页';
				}
			}
		}
	}
</script>

<style lang="scss">
  .preview-btn {
    display: inline-block;
    vertical-align: middle;
    font-size: 24rpx;
    padding: 8rpx 18rpx;
    border-radius: 8rpx;
    margin-left: 20rpx;
    color: $uni-color-primary;
    border: 1px solid $uni-color-primary;
    line-height: 1.2;
  }
	.set_main {
		overflow: hidden;
		padding: 0 32rpx;
		min-height: calc(100vh - 128rpx);
	}

	.tips_wrapper {
		height: 50rpx;
		padding: 0 32rpx;
		margin: 32rpx 0;
		border-radius: 8rpx;
		background-color: #DBECE5;
	}

	.set_top,
	.set_content {
		background-color: #fff;
		padding: 32rpx;
		margin: 32rpx 0;
		border-radius: 16rpx;
	}

	.set_title {
		font-size: 28rpx;
		line-height: 40rpx;
		margin-top: 48rpx;

		&:first-child {
			margin-top: 0;
		}
	}

	.set_wrapper {
		flex: 1;
		display: flex;
		flex-wrap: wrap;

		view {
			font-size: 26rpx;
			line-height: 36rpx;
			padding: 16rpx 22rpx;
			border-radius: 4rpx;
			background-color: #F3F3F3;
			margin: 16rpx 12rpx 0 0;
			text-align: center;
			min-width: 76rpx;
			position: relative;

			&.active {
				color: #05B570;
				background-color: rgba(6, 161, 126, 0.08);
			}

			&.huise {
				color: #fff;
				background-color: rgba(0, 0, 0, 0.1);
			}
		}
	}

	.set_des {
		font-size: 22rpx;
		line-height: 30rpx;
		color: #05B570;
		margin-top: 16rpx;
	}

	.set_tectorial {
		margin-top: 16rpx;
		border-radius: 16rpx;
		background-color: #F4FAFB;
		padding: 30rpx 24rpx;
		display: flex;
	}

	.set_pitch {
		font-size: 20rpx;
		line-height: 28rpx;
		text-align: center;
		margin: 12rpx 44rpx 12rpx 0;
		position: relative;

		view {
			&:first-child {
				width: 80rpx;
				height: 80rpx;
				border-radius: 8rpx;
				color: #fff;
				display: flex;
				align-items: center;
				justify-content: center;
				margin-bottom: 2rpx;

				&.active {
					color: #222;
					box-sizing: border-box;
					border: 1px solid #222;
				}
			}

			&:nth-child(3) {
				top: 0;
				left: 0;
				width: 80rpx;
				height: 80rpx;
				border-radius: 8rpx;
				position: absolute;
				background: url(https://dy.sykj365.com/uploads/mini/xuanzhong1@2x.png) no-repeat center rgba(0, 0, 0, 0.4);
				background-size: 48rpx 48rpx;
			}
		}
	}

	.text_wrapper {
		width: 460rpx;
		height: 320rpx;
		overflow: hidden;
		border: 1px solid #E8E8E8;

		.text_img {
			width: 230rpx;
			height: 100%;
			margin: 0 auto;
			// margin: 0 0 0 auto;
		}

		.imgs_ {
			width: 100%;
			height: 100%;
			margin: 0 0 0 auto;
		}

		textarea {
			width: 100%;
			height: 100%;
			box-sizing: border-box;
			padding: 32rpx;
		}
	}

	.text_add {
		width: 100%;
		height: 100%;
		background-color: #F3F3F3;
	}

	.btn_wrapper {

		view,
		navigator {
			color: #7A7A7A;
			width: 100rpx;
			height: 52rpx;
			border-radius: 80rpx;
			border: 1rpx solid #E8E8E8;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 32rpx 0;
		}
	}

	.set_bottom {
		width: 100%;
		position: fixed;
		bottom: 0;
		background-color: #fff;
		box-shadow: 0px 5px 10px #e8e8e8;
		box-sizing: border-box;
		padding: 18rpx 32rpx 38rpx;
	}

	.set_yulan {
		width: 152rpx;
		height: 72rpx;
		box-sizing: border-box;
		border: 1px solid #E8E8E8;
		border-radius: 56rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		margin-right: 16rpx;
	}

	.p_btn {
		width: 208rpx;
		margin: 0;
	}

	.pick_text {
		position: absolute;
		top: 60px;
		z-index: 999;
		width: 100%;
	}
</style>
